/*上传视频 控件 Flash由王显珉新做的*/
XN.SingleUp = {
	//============成员
	flash:null,
	inited:false,
	isIdlesse:true,		//是否空闲
	obj:{},
	checkUrl:"/upload/check.do",
	resTypes:{
		vidoe:5,
		music:1,
		photo:6
	},
	//============用户方法
	init:function(_id,_url,_upTo,_fileTypes,_fileSize){
		var f = document.createElement("div");
		f.className = "hiddenFlash";
		document.body.appendChild(f);
		if(FWK.isIE){
			f.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="0" height="0" id="'+_id+'"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+_url+'?type=XN.SingleUp." /></object>';
		}
		else{
			f.innerHTML = '<embed src="'+_url+'?type=XN.SingleUp." width="0" height="0" name="'+_id+'" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		}
		XN.SingleUp.flash = ((navigator.appName.indexOf("Microsoft") != -1))?window[_id]:document[_id];
		XN.SingleUp.url = _upTo;
		XN.SingleUp.types = _fileTypes;
		XN.SingleUp.size = FWK.isNum(_fileSize)?_fileSize:1024*1024*1024*10;//10G
		XN.SingleUp.sizeCheck = FWK.isStr(_fileSize)?XN.SingleUp.resTypes[_fileSize]:null;
	},
	/**============我同Flash交互*/
	//浏览
	browse:function(){
		if (!XN.SingleUp.inited) {
			alert("Flash 加载失败...");
			return;
		}
		if (!XN.SingleUp.isIdlesse) {
			return;
		}
		XN.SingleUp.flash.browse(XN.SingleUp.types,XN.SingleUp.size);
	},
	upLoad:function(_obj){
		if (!XN.SingleUp.isIdlesse) {
			return;
		}
		XN.SingleUp.isIdlesse = false;
		if (_obj) {
			FWK.extend(XN.SingleUp.obj,_obj);
		}
		
		var strs = [],url = XN.SingleUp.url;
		for(var n in XN.SingleUp.obj){
			if(FWK.isStr(XN.SingleUp.obj[n]) || FWK.isNum(XN.SingleUp.obj[n])){
				strs.push(n + "=" + encodeURIComponent(XN.SingleUp.obj[n]));
			}
		}
		if(!FWK.isIE){
			//;WOWNIU_KEY="+XN.getCookieQuery("WOWNIU_KEY")+"
			strs.push("sessionId=" + XN.getCookieQuery("WOWNIU_KEY"));
		}
		if(strs.length>0){
			url = url.indexOf("?")>-1?url + "&" + strs.join("&"):url + "?" + strs.join("&");
		}
		//alert(url);
		XN.SingleUp.flash.upLoad(url);
		strs = null;delete strs;
		url = null;delete url;
		_obj = null;delete _obj;
	},
	delFile:function(){
		if(!XN.SingleUp.isIdlesse){
			return ;
		}
		XN.SingleUp.flash.delFile();
	},
	/**============Flash同我交互*/
	//Flash加载完毕
	initComplete:function(){
		XN.SingleUp.inited = true;
	},
	//Flash选择
	onSelect:function(_fileType,_fileName,_fileSize){
		if(XN.SingleUp.sizeCheck && _fileSize){
			FWK.Util.AjaxList.open(XN.SingleUp.checkUrl,"POST",{resType:XN.SingleUp.sizeCheck,size:_fileSize,type:_fileType},XN.SingleUp.checkComplete.bind(XN.SingleUp,[_fileType,_fileName]));
		}
		else{
			XN.SingleUp.onSelected(_fileType,_fileName);
		}
	},
	checkComplete:function(_fileType,_fileName,_xml){
		if(_xml){
			var ret = XN.checkResponse(_xml);
			if(ret==true){
				this.onSelected(_fileType,_fileName);
			}
			else{
				this.error(ret.des);
			}
		}
		else{
			this.onSelected(_fileType,_fileName);
		}
	},
	onSelected:function(_fileType,_fileName){
		delete XN.SingleUp.obj;XN.SingleUp.obj = {};
		XN.SingleUp.obj.fileType = _fileType
		try{XN.SingleUp.$onSelect(_fileName,_fileType);}catch(e){}
	},
	//出错
	error:function(_mes){
		XN.SingleUp.isIdlesse = true;
		if(_mes=="文件尺寸太大"){
			_mes = "上传文件太大";
		}
		try{XN.SingleUp.$error(_mes);}catch(e){}
	},
	//上传成功 后调用
	uploadComplete:function(_mes){
		XN.SingleUp.isIdlesse = true;
		XN.SingleUp.delFile();
		try{XN.SingleUp.$uploadComplete(_mes);}catch(e){}
	},
	//上传进度
	onProgress:function(_percent){
		try{XN.SingleUp.$onProgress(_percent);}catch(e){}
	},
	//帮助Flash调试
	debug:function(_mess){
		//alert("debug：\n" + _mess);
	}
}